package ldh.im.admin.service;

import java.text.Collator;
import java.text.Normalizer;

public class ChineseInitials {
    public static String getInitials(String input) {
        StringBuilder initials = new StringBuilder();
        Collator collator = Collator.getInstance(java.util.Locale.CHINA);

        for (int i = 0; i < input.length();) {
            int codePoint = Character.codePointAt(input, i);
            if (isChinese(codePoint)) {
                initials.append(getInitial(codePoint));
            }
            i += Character.charCount(codePoint);
        }

        return initials.toString();
    }

    private static boolean isChinese(int codePoint) {
        return Character.UnicodeBlock.of(codePoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || Character.UnicodeBlock.of(codePoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || Character.UnicodeBlock.of(codePoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || Character.UnicodeBlock.of(codePoint) == Character.UnicodeBlock.GENERAL_PUNCTUATION
                || Character.UnicodeBlock.of(codePoint) == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION;
    }

    private static char getInitial(int codePoint) {
//        String[] pinyins = Collator.getInstance(java.util.Locale.CHINA).getSortKey(new String(Character.toChars(codePoint), 0, Character.charCount(codePoint))).split(" ");
//        return pinyins[0].charAt(0);
        return '0';
    }

    public static void main(String[] args) {
        String input = "中文首字母提取";
        String initials = getInitials(input);
        System.out.println(initials); // 输出可能是 "ZFZXTQ"
    }
}
